package com.credit.mola.app.utils.analysis.http

import com.credit.mola.app.utils.analysis.AnalysisBuilder
import com.credit.mola.app.utils.http.HttpHelper
import com.credit.mola.app.utils.http.IHttpCallback
import org.json.JSONObject


object UrlHelper {

    fun combineUrl(): String {
        if (AnalysisBuilder.host.isBlank() or
            AnalysisBuilder.zone.isBlank() or
            AnalysisBuilder.pathCommon.isBlank()
        ) {
            return ""
        }

        val zone = AnalysisBuilder.zone
        AnalysisBuilder.zone = zone.replace("/", "")

        val pathCommon = AnalysisBuilder.pathCommon
        AnalysisBuilder.pathCommon = if (pathCommon.startsWith("/")) {
            pathCommon.replace("/", "")
        } else {
            pathCommon
        }

        return AnalysisBuilder.host + "/" + AnalysisBuilder.zone + "/" + AnalysisBuilder.pathCommon
    }
}

object AnalysisHttpUtils {
    fun postData(toUrl: String, body: String) {
        if (toUrl.isBlank()) return
        if (body.isBlank()) return

        HttpHelper.post(toUrl, JSONObject(body),object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
            }
            override fun onRequestError(error: JSONObject) {
            }
            override fun onRequestFinish() {
            }
        })
    }
}


